<?php
header("Access-Control-Allow-Origin:*");
require("../lib/init.php");
require("../pojo/token.php");
require("../pojo/role.php");
$roleName = $_POST['roleName'];
$token = $_POST['token'];
if (empty($roleName) or empty($token)) exit("缺少必要参数！");
if (!checkToken($token)) {
    $code = 400;
    $msg = "没有权限";
} else {
    if (!checkRole($roleName)) {
        $sql = "insert into role (roleName) values ('$roleName')";
        if (!MQuery($sql)) {
            $code = 400;
            $msg = "添加失败！";
        } else {
            $code = 200;
            $msg = "添加成功！";
        }
    }else{
        $code = 400;
        $msg = "对不起，角色已经存在！";
    }
}

echo json_encode(resultmsg($code, $msg));
